package com.lzq.leetcode.lanqiao;

import java.lang.reflect.Array;
import java.util.Arrays;

public class s3552 {

    public static void main(String[] args) {

        int height = 5;
        int[] input = new int[]{1, 0, 1, 0, 1};
        int[] sum = new int[]{0};
        dfs(input, new int[4], 5, 0, sum);

        System.out.println(sum[0]);
    }

    public static void dfs(int[] input, int[] output, int len, int index, int[] sum) {
        if (len == 1) {
            // and
            sum[0] += input[0];
        } else if (index == len-1) {
            // 跳转到下一层
            int[] newInput = Arrays.copyOf(output, len-1);
            dfs(newInput, new int[len-2], len-1, 0, sum);
        } else {
            // 遍历每一种门
            output[index] = input[index] & input[index + 1];
            dfs(input, output, len, index + 1, sum);
            // or
            output[index] = input[index] | input[index + 1];
            dfs(input, output, len, index + 1, sum);
            // xor
            output[index] = input[index] ^ input[index + 1];
            dfs(input, output, len, index + 1, sum);
        }
    }
}
